﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CountNumberCtrl : MonoBehaviour {

	public Animator startNumbers;
	public GameObject numberContains;
	
	List<GameObject> listCountNumbers;
	int numberIdx = -1;
	
	void Awake()
	{
		listCountNumbers = new List<GameObject>();
		for (int i = 0; i < numberContains.transform.childCount; i++) {
			listCountNumbers.Add(numberContains.transform.GetChild(i).gameObject);
		}
	}

	// Use this for initialization
	IEnumerator Start () {
		yield return new WaitForSeconds(4f);
		startNumbers.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	
	public void OnClickedNext()
	{
//		if(startNumbers.enabled) return;
//		startNumbers.gameObject.SetActive(false);

		bool flagIncrease = false;
		if(numberIdx < 0) {
			numberIdx = 0;
			flagIncrease = true;
		}
		
		if(numberIdx < listCountNumbers.Count){
			if(listCountNumbers[numberIdx].GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime > 1f || flagIncrease){
				if(numberIdx < listCountNumbers.Count){
					if(!flagIncrease)
						numberIdx++;
					if(numberIdx >= listCountNumbers.Count) {
						Debug.LogWarning("Het so roi ne");
						return;
					}
						
					listCountNumbers[numberIdx].SetActive(true);
					if(numberIdx > 0)
						listCountNumbers[numberIdx - 1].SetActive(false);
					
				}
				
			}
		}
	}
	
	public void OnClickedHome()
	{
		Debug.Log("Home");
		Debug.Log(listCountNumbers[0].GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime);
	}
}
